const mysql = require("mysql")

const config = require("./dbconfig")

const db = mysql.createPool({
  ...config
})

db.getConnection((err, conn) => {
  if (err) {
    console.log("+++++++++++++++++++++++++++数据库连接失败：" + err.stack)
  }
  console.log("++++++++++++++++++++数据库连接成功++++++++++++++++++++")
})

function query(sql, values) {
  return new Promise((resolve, reject) => {
    db.query(sql, values, (err, results) => {
      if (err) {
        reject(err)
      } else {
        resolve(results)
      }
    })
  })
}
module.exports = {
  query
}
